<?php

$line = array('ACCOUNT_NUMBER', 'INST_FIRST_NAME', 'INST_LAST_NAME', 'SALUTATION', 'COMPANY_NAME', 'PO_BOX', 'LANGUAGE', 'BILL_STREET', 'BILL_HOUSE_NO', 'BILL_ZIP', 'BILL_CITY');
$csv->addRow($line);

WHILE($r1 = mysql_fetch_array($result))
  {
    if(strpos($r1['inst_first_name'],'#') !== false) {
    	$r1['inst_first_name'] = "";
    	$r1['salutation'] = "";
    }
    if(strpos($r1['inst_last_name'],'#') !== false) {
    	$r1['inst_last_name'] = "";
    	$r1['salutation'] = "";
    }
    if(strlen($r1['company_name']) == 1) { $r1['company_name'] = ""; }
   
        
    $line = array($r1['account_number'], $r1['inst_first_name'], $r1['inst_last_name'], $r1['salutation'], trim($r1['company_name']), $r1['po_box'], $r1['language'], $r1['bill_street'], $r1['bill_house_no'], $r1['bill_zip'], $r1['bill_city']);
    $csv->addRow($line);

    $bid = $r1['id'];
    mysql_query("UPDATE blacklists SET letter = 2 WHERE id = '$bid'");
  }

$datum = date("d.m.Y");
$end = ".csv";
$title = "Export_Blacklist_SchmidFehr_".$datum.".csv";
echo $csv->render($title);

?>